<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>电脑信息添加页面</title>
<link rel="stylesheet" href="../layui/css/layui.css" media="all">
<style>
.layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
	height: 34px;
	line-height: 34px;
	padding: 0 8px;
}
</style>
</head>
<body>
	<form class="layui-form" action="">
	<div class="layui-form-item" style="margin-top: 20px;" onsubmit="false">
		<div class="layui-form-item">
			<label class="layui-form-label">电脑名称:</label>
			<div class="layui-input-inline" style="width: 350px;">
				<input type="text" id="c_name" name="c_name" required=""
			 lay-reqtext="电脑名称不能为空" placeholder="请输入电脑名称"
					autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">电脑类型:</label>
			<div class="layui-input-inline" style="width: 350px;">
				<input type="text" id="c_no" name="c_no" required=""
				 lay-reqtext="电脑编号不能为空" placeholder="请输入电脑编号"
					autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">所属阅览室:</label>
			
			
			<div class="layui-input-inline" style="width: 120;">
				<select name="c_readrooms_id" id="c_readrooms_id"
					class="layui-input" lay-verify="required">
					<option value="">请选择所属阅览室</option>
					<option value="1">1号电脑房</option>
					<option value="2">2号电脑房</option>
				</select>
			</div>
		</div>
		<div class="layui-btn-container" style="text-align: center;">
			<button class="layui-btn" lay-filter="computersBtu" lay-submit="">
				添加</button>
		</div>
		</div>
	</form>
	<script type="text/javascript" src="../layui/layui.js"></script>
	<script>
		//加载了layui的form模块
		layui.use([ 'form' ], function() {
			var form = layui.form;
			var $ = layui.jquery; //引入jquery
			//监听提交
			form.on('submit(computersBtu)', function(data) {
				var d = data.field; //表单中的数据，定义一个对象来接收
				d.method = "add";
				//通过ajax向数据库提交数据了
				console.log(d); //提交之前的一个数据验证、通过打印的方式先手动的去判断一下这个数据
				var url = '../addComputers';
				$.post(url, d, function(data) {
					if (data.count > 0) {
						console.log('添加成功');
						var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
						parent.layer.close(index); //关闭窗口
					}
				}, "json");
				return false;
			});
		});
	</script>
</body>
</html>